package cn.redcoral.messageplus.data.model.entity;

import cn.hutool.core.bean.BeanUtil;
import cn.redcoral.messageplus.data.model.dto.GroupDto;
import cn.redcoral.messageplus.data.model.vo.GroupVo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 群组
 * @author mo
 **/
@Data
@TableName("mp_group")
public class Group implements Serializable {
    /**
     * 群组ID
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;
    /**
     * 创建者ID
     */
    private String createUserId;
    /**
     * 群组名称
     */
    private String name;
    /**
     * 是否开启禁言
     */
    private Boolean isForbiddenSpeak = false;
    /**
     * 用户ID列表
     */
    @TableField(exist = false)
    private List<String> clientIdList = new ArrayList<>();

    public Group() {}
    public Group(String name) {
        this.name = name;
    }

    public static Group BuildGroupPo(GroupVo groupVo) {
        Group group = new Group();
        BeanUtil.copyProperties(groupVo, group);
        return group;
    }

    /**
     * 向用户ID列表添加ID
     * @param clientId 用户ID
     */
    public Group addClientId(String clientId) {
        this.clientIdList.add(clientId);
        return this;
    }

}
